<?php

class TdPasswordField extends TdTextField {

	var $compare_field;
	
  function __construct($id, $template="") {
    parent::__construct($id, $template);
  }

  function __toString() {
  	$pout = parent::__toString();
  	if ($pout != "") {
  		return $pout;
  	}
  
  	ob_start();
  
  	if (isset($this->label)) {
  		print($this->label);
  	}
  	print("<input id=\"".$this->id."\" name=\"".$this->name."\" type=\"password\"");
  	if (isset($this->size)) print(" size=\"".$this->size."\"");
  	if (isset($this->maxlength)) print(" maxlength=\"".$this->maxlength."\"");
  	if (isset($this->cssclass)) print(" class=\"".$this->cssclass."\"");
  	print(" value=\"".$this->value."\"\/>");
  
  	return ob_get_clean();
  }
  
  function setCompare($obj) {
  	$this->compare_field = $obj;
  }
  
  function getCompare() {
  	return $this->compare_field;
  }
  
  function doValidate() {
  	parent::doValidate();
  	
  	if (($this->getValue() != "") && isset($this->compare_field)) {
  		if ($this->getValue() != $this->compare_field->getValue()) {
  			$this->addErrorMessage("Il campo ".$this->getLabel()->getValue()." non corrisponde con ".$this->compare_field->getLabel()->getValue().".");
  		}
  	}
  }
}

?>
